﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyDBconnection;
namespace Thesis_2
{
    public partial class frmLogin : Form
    {
        DatabaseConnection dbcon = new DatabaseConnection();
        public frmLogin()
        {
            InitializeComponent();
            btncancel.Click += new EventHandler(btncancel_Click);
            btnlogin.Click += new EventHandler(btnlogin_Click);
        }

        void btnlogin_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text == "")
            {
                MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserName.Focus();
                return;
            }
            if (txtPassword.Text == "")
            {
                MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPassword.Focus();
                return;
            }
            dbcon.dbconnection();
            dbcon.mylogin("SELECT * from tbluserinfo WHERE Username = '" + txtUserName.Text + "' and Password= '" + this.txtPassword.Text + "'");
            if (dbcon.tbl.Rows.Count > 0)
            {
                MessageBox.Show("Login Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
                dbcon.DBClose();
                frmMain frmM = new frmMain();
                frmM.passvalue = txtUserName.Text;
                frmM.Show();
            }
            else
            {
                MessageBox.Show("Invalid Username or Password");
                txtUserName.Text = "";
                txtPassword.Text = "";
                txtUserName.Focus();

            }
            dbcon.DBClose();
        }

        void btncancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
            
        }
    }
}
